//
//  LPKHomeViewCell.m
//  Demo-01
//
//  Created by 李平宽 on 2017/1/21.
//  Copyright © 2017年 com.lpk. All rights reserved.
//

#import "LPKHomeViewCell.h"
#import "UIColor+Addition.h"
#import "UILabel+Addition.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
@interface LPKHomeViewCell ()

/**
 标题
 */
@property(nonatomic,copy)UILabel* lab;

/**
 图片
 */
@property(nonatomic,strong)UIImageView *img;

/**
 农历
 */
@property(nonatomic,strong)UILabel *lun;
@end
@implementation LPKHomeViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 添加子控件
        [self setupUI];
        
    }
    return self;
}
- (void)setupUI
{
   
    UILabel *lab = [UILabel makeLabelText:@"" andTextColor:[UIColor colorWithHex:0x000000] andTextFont:14];
    [self.contentView addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.offset(10);
        make.right.offset(-8);
    }];
    lab.numberOfLines = 0;
   
    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholderImage"]];
    [self.contentView addSubview: img];

    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab.mas_bottom).offset(8);
        make.left.offset(10);
        make.right.offset(-8);
        
    }];
    

    UILabel *lun =  [UILabel makeLabelText:@"" andTextColor:[UIColor colorWithHex:0x7686a8] andTextFont:13];
    [self.contentView addSubview:lun];
    [lun mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(img.mas_bottom).offset(8);
        make.left.offset(9);
        make.bottom.offset(-8);
    }];
     _lab = lab;
     _img = img;
    _lun = lun;
    
}
- (void)setModel:(LPKHomeMode *)model
{
    _model = model;
    _lab.text = model.title;
    [_img sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
    if (![model.pic isEqualToString:@""])
    {
        
        CGFloat imgRealW = _img.image.size.width;
        CGFloat imgRealH = _img.image.size.height;
        CGFloat imagViewHeight = 200;
        CGFloat imagViewwith = imagViewHeight * imgRealW / imgRealH;
        [_img sizeToFit];
        [_img mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.offset(imagViewHeight);
            make.width.offset(imagViewwith);
            make.top.equalTo(_lab.mas_bottom).offset(8);
        }];
        
    }else
    {
        [_img mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.width.offset(0);
            make.top.equalTo(_lab.mas_bottom).offset(0);
        }];
    }
    _lun.text = model.lunar;
    
    
}

@end
